package com.example.stroebackstage.filter;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class LoginStatusFilter implements Filter {
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        HttpServletRequest req = (HttpServletRequest) request;
        HttpServletResponse resp = (HttpServletResponse) response;
        if(req.getSession().getAttribute("admin") != null){
            chain.doFilter(req,resp);
        }else {
            req.setAttribute("login_massage","请先登录");
            req.getRequestDispatcher("/admin_login.jsp").forward(req,resp);
        }
    }
}